package mobi.weq.util.edinburgh;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import mobi.weq.util.Util;
import mobi.weq.util.map.Coordinate;

public class EdinburghPlaces {
	private static Map<String, Double> nMap;

	private static Coordinate getCoordsFromString(String c) {
		String[] tokens = c.substring(1, c.length() - 1).split(",");
		double lat = Double.valueOf(tokens[0].trim());
		double lng = Double.valueOf(tokens[1].trim());
		return new Coordinate(lat, lng);
	}

	private static String getGridIDFromString(String c) {
		String[] tokens = c.substring(1, c.length() - 1).split(",");
		double lat = Double.valueOf(tokens[0].trim());
		double lng = Double.valueOf(tokens[1].trim());

		return Util.getGridId(lat, lng);
	}

	public static void main(String[] args) {
		Map<String, Integer> map = getPollutedPlacesMap();
		System.out.println(Collections.max(map.values()));
		System.out.println(Collections.min(map.values()));
		System.out.println(map.size());
		System.out.println(map);
		System.out.println(getPollutedPlacesMapNormalized());
		System.out.println(POSSIBLE_POLLUTION_LOCATIONS_STRING.length);
	}

	public static Map<String, Integer> getPollutedPlacesMap() {
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (String c : POSSIBLE_POLLUTION_LOCATIONS_STRING) {
			String key = getGridIDFromString(c);
			if (!map.containsKey(key)) {
				map.put(key, 0);
			}
			map.put(key, map.get(key) + 1);
		}
		return map;
	}

	public static Map<String, Double> getPollutedPlacesMapNormalized() {
		if (nMap != null)
			return nMap;

		nMap = new HashMap<String, Double>();
		Map<String, Integer> map = getPollutedPlacesMap();

		double max = Collections.max(map.values());
		double min = Collections.min(map.values());
		double range = max - min;
		for (String key : map.keySet()) {
			double val = 1.5 + (map.get(key) - min) / range;
			nMap.put(key, val);
		}
		return nMap;
	}

	public static String[] POSSIBLE_POLLUTION_LOCATIONS_STRING = { "(55.982155, -3.177251999999953)", "(55.953129, -3.189681000000064)",
			"(55.953854, -3.196282999999994)", "(55.951973, -3.175567000000001)", "(55.953844, -3.1869389999999385)", "(55.946776, -3.185958000000028)",
			"(55.951068, -3.1882459999999355)", "(55.950902, -3.1956860000000233)", "(55.855378, -3.160194000000047)", "(55.948304, -3.206654999999955)",
			"(55.952714, -3.172272000000021)", "(55.953525, -3.1959739999999783)", "(55.942082, -3.269362000000001)", "(55.96162, -3.165211999999997)",
			"(55.94878, -3.195609999999988)", "(55.95366, -3.195607999999993)", "(55.948776, -3.1956230000000687)", "(55.942857, -3.203905999999961)",
			"(55.951082, -3.19075399999997)", "(55.930838, -3.208782000000042)", "(55.952286, -3.1933139999999867)", "(55.946015, -3.15963499999998)",
			"(55.949485, -3.190868000000023)", "(55.860772, -3.0824720000000525)", "(55.939061, -3.23183599999993)", "(55.977038, -3.1727620000000343)",
			"(55.949917, -3.1908149999999296)", "(55.909305, -3.3199549999999363)", "(55.945457, -3.2435950000000275)", "(55.956641, -3.185467000000017)",
			"(55.95069, -3.1747480000000223)", "(55.952125, -3.2265310000000227)", "(55.946119, -3.209726000000046)", "(55.948809, -3.1931409999999687)",
			"(55.952381, -3.193273999999974)", "(55.953182, -3.193956000000071)", "(55.955509, -3.193715999999995)", "(55.927596, -3.247739000000024)",
			"(55.942027, -3.2032400000000507)", "(55.941251, -3.1917009999999664)", "(55.936557, -3.1572459999999865)", "(55.952511, -3.2080459999999675)",
			"(55.956596, -3.1562679999999546)", "(55.89455, -3.0917799999999716)", "(55.944516, -3.189241000000038)", "(55.953641, -3.189261999999985)",
			"(55.946101, -3.2290289999999686)", "(55.97608, -3.1697599999999966)", "(55.942235, -3.2408060000000205)", "(55.947566, -3.2048320000000103)",
			"(55.945874, -3.1989979999999605)", "(55.971181, -3.2784639999999854)", "(55.949413, -3.1937319999999545)", "(55.95237, -3.1918210000000045)",
			"(55.948549, -3.191872999999987)", "(55.950631, -3.184859999999958)", "(55.953001, -3.2046890000000303)", "(55.94038, -3.1718399999999747)",
			"(55.94714, -3.192837000000054)", "(55.922853, -3.136641999999938)", "(55.942009, -3.148531000000048)", "(55.948986, -3.1946140000000014)",
			"(55.938409, -3.3144829999999956)", "(55.92716, -3.163783999999964)", "(55.941236, -3.181598000000008)", "(55.949571, -3.1875350000000253)",
			"(55.950579, -3.185012000000029)", "(55.930306, -3.0739429999999857)", "(55.947277, -3.205024999999978)", "(55.946623, -3.192289999999957)",
			"(55.977315, -3.244891999999936)", "(55.94991, -3.335172000000057)", "(55.938458, -3.1888569999999845)", "(55.926694, -3.2899159999999483)",
			"(55.9488, -3.2160129999999754)", "(55.916028, -3.2046679999999697)", "(55.951705, -3.1795039999999517)", "(55.925863, -3.140243000000055)",
			"(55.946832, -3.204430000000002)", "(55.956182, -3.187857000000008)", "(55.951297, -3.1780169999999544)", "(55.938321, -3.226138999999989)",
			"(55.928647, -3.259645999999975)", "(55.954071, -3.195836999999983)", "(55.944778, -3.1872829999999794)", "(55.951388, -3.1794399999999996)",
			"(55.941407, -3.3054630000000316)", "(55.951309, -3.189442999999983)", "(55.905602, -3.1330990000000156)", "(55.923739, -3.2362699999999904)",
			"(55.946232, -3.1907019999999875)", "(55.94647, -3.194419000000039)", "(55.939243, -3.2019359999999324)", "(55.945038, -3.1858499999999594)",
			"(55.951837, -3.224250999999981)", "(55.94305, -3.1875250000000506)", "(55.943225, -3.2437130000000707)", "(55.952331, -3.212305000000015)",
			"(55.938622, -3.052595999999994)", "(55.96493, -3.299686000000065)", "(55.96259, -3.2327149999999847)", "(55.952528, -3.204791)",
			"(55.903045, -3.180280000000039)", "(55.946238, -3.1850050000000465)", "(55.952648, -3.2014629999999897)", "(55.923964, -3.1762350000000197)",
			"(55.952868, -3.2020730000000412)", "(55.945125, -3.188633999999979)", "(55.948779, -3.235163000000057)", "(55.938317, -3.20895100000007)",
			"(55.95283, -3.198599999999942)", "(55.960516, -3.2128979999999956)", "(55.931663, -3.2881059999999707)", "(55.94271, -3.1891500000000406)",
			"(55.881279, -3.1046010000000024)", "(55.887362, -3.2116509999999607)", "(55.929905, -3.175555000000031)", "(55.951489, -3.1798730000000432)",
			"(55.942315, -3.204727999999932)", "(55.902641, -3.220968999999968)", "(56.029915, -3.3012410000000045)", "(55.936863, -3.1999960000000556)",
			"(55.861907, -3.067635999999993)", "(55.938032, -3.1929489999999987)", "(55.957129, -3.1862619999999424)", "(55.921708, -3.136437000000001)",
			"(55.882851, -3.068467999999939)", "(55.949449, -3.2047619999999597)", "(55.94719, -3.1878600000000006)", "(55.95118, -3.1859269999999924)",
			"(55.912164, -3.2537250000000313)", "(55.909007, -3.321013999999991)", "(55.934248, -3.1038129999999455)", "(55.940774, -3.2419230000000425)",
			"(55.941008, -3.1796679999999924)", "(55.95683, -3.1881960000000618)", "(55.945352, -3.2338110000000597)", "(55.964188, -3.2844029999999975)",
			"(55.963394, -3.217581999999993)", "(55.94696, -3.2197869999999966)", "(55.961361, -3.1811549999999897)", "(55.944937, -3.199698000000012)",
			"(55.932897, -3.287521999999967)", "(55.944373, -3.1868930000000546)", "(55.914759, -3.2366250000000036)", "(55.966849, -3.166527999999971)",
			"(55.952547, -3.1739939999999933)", "(55.950161, -3.1934350000000222)", "(55.950006, -3.1920239999999467)", "(55.951172, -3.2054560000000265)",
			"(55.946394, -3.190187000000037)", "(55.950545, -3.1856809999999314)", "(55.949324, -3.190123999999969)", "(55.946705, -3.1852589999999736)",
			"(55.953546, -3.185967000000005)", "(55.954407, -3.221634999999992)", "(55.949181, -3.18453599999998)", "(55.917614, -3.2901259999999866)",
			"(55.904214, -3.151198000000022)", "(55.948595, -3.1999130000000378)", "(55.95017, -3.1802370000000337)", "(55.970783, -3.1508870000000115)",
			"(55.945075, -3.3047900000000254)", "(55.865583, -3.1995379999999614)", "(55.914232, -3.1529860000000554)", "(55.930948, -3.219551000000024)",
			"(55.9722, -3.171338999999989)", "(55.926631, -3.1674659999999903)", "(55.95772, -3.1872869999999693)", "(55.944463, -3.200929999999971)",
			"(55.9229, -3.1880240000000413)", "(55.952288, -3.2182209999999714)", "(55.946578, -3.0358280000000377)", "(55.948321, -3.192299999999932)",
			"(55.949563, -3.1915989999999965)", "(55.937526, -3.1809900000000653)", "(55.955049, -3.142270000000053)", "(55.951686, -3.1962919999999713)",
			"(55.931648, -3.227390000000014)", "(55.935493, -3.1756370000000516)", "(55.94409, -3.198333000000048)", "(55.952109, -3.189830000000029)",
			"(55.943884, -3.218525999999997)", "(55.886777, -3.338281000000052)", "(55.941354, -3.2175589999999374)", "(55.967558, -3.198511999999937)",
			"(55.951708, -3.198142999999959)", "(55.909915, -3.3185680000000275)", "(55.950785, -3.361452999999983)", "(55.970441, -3.180900000000065)",
			"(55.908921, -3.256136999999967)", "(55.901656, -3.044952999999964)", "(55.976443, -3.1954769999999826)", "(55.967012, -3.224604999999997)",
			"(55.952861, -3.194472000000019)", "(55.939103, -3.2365760000000137)", "(55.971039, -3.163968999999952)", "(55.932594, -3.209769999999935)",
			"(55.955162, -3.1500499999999647)", "(55.947064, -3.20761200000004)" };
}
